<?php

class OrganizationUsersList extends UsersAdminAbstractList
{

    function __construct()
    {
        parent::__construct( 'user_organization', 10, '',
                array( 'name' => 1, 'fiscal_id' => 1 ) );
        $this->simpleusers = false;
    }

    function crear()
    {
        $sql = 'INSERT INTO users (resource, organization, name,first_surname,second_surname,fiscal_id,username,password, mail) VALUES (\'R_USR\',' . $_SESSION[ 'organization' ] . ',' . MyLink::quote( $_POST[ 'name' ] ) . ', ' . MyLink::quote( $_POST[ 'first_surname' ] ) . ', ' . MyLink::quote( $_POST[ 'second_surname' ] ) . ', ' . MyLink::quote( $_POST[ 'fiscal_id' ] ) . ', ' . MyLink::quote( $_POST[ 'username' ] ) . ', MD5(' . MyLink::quote( $_POST[ 'password' ] ) . ', ' . MyLink::quote( $_POST[ 'username' ] ) . ') )';
        MyLink::$default->execute( $sql );
        $id = MyLink::$default->insert_id;

        Security::addResourceEdges( array( 'R_USR' => array( $id ) ),
                'R_USR_ORG', $_SESSION[ 'organization' ] );

        if ( isset( $_POST[ 'level' ] ) && $_POST[ 'level' ] == '1' ) {

            Security::addResourceEdges( array( 'R_USR' => array( $id ) ),
                    'R_ADM_ORG', $_SESSION[ 'organization' ] );
            Security::addUserRoles( $id,
                    array( 'ADM_ORG' => array( $_SESSION[ 'organization' ] ), 'USER' => array(
                    $id ) ) );
        }

        Security::addPrivilege( 'USER', $id, 'R_MIL_USR', $id, 'MilestoneAdmin' );
    }

}

?>
